import type { GreasyForkElements } from '../../../../../../../../../types/constants/personalization/greasy_fork'
import { ThemeVarService } from '../../../../../../../../../lib/abstract/style/theme_var/service'
import { ICON_IDS } from '../../../../../../../../../lib/icons/types/constants'
import {
  AppStyleCollections,
  BLOCKQUOTE_STYLES,
  PAGE_ELEMENTS,
  SUPPORTED_PLATFORMS,
} from '../../../../../../../../../types/constants'
import { StylesService } from '../../../../../../../../../types/constants/styles'
import { ScriptProcessor } from '../../module/script_processor'
import { CommonPage } from '../common'

// 测试链接
// 1）https://greasyfork.org/zh-CN/users/1507611-pamela-mcninchu （封禁用户）
// 2）https://greasyfork.org/zh-CN/users/104167-stephenp （管理员）
export class UserPage {
  elements: GreasyForkElements = PAGE_ELEMENTS[SUPPORTED_PLATFORMS.GREASY_FORK]
  private static instance: UserPage
  private themeVarService: ThemeVarService = ThemeVarService.getInstance()
  private stylesService: StylesService = StylesService.getInstance()
  private commonPage: CommonPage = CommonPage.getInstance()
  private scriptProcessor: ScriptProcessor = ScriptProcessor.getInstance()

  /**
   * 获取单例实例
   */
  public static getInstance(): UserPage {
    if (!UserPage.instance) {
      UserPage.instance = new UserPage()
    }
    return UserPage.instance
  }

  init(): void {
    this.scriptProcessor.init()
  }

  getMainStyles(): string {
    return `
.width-constraint {
  background-color: var(${this.themeVarService.default.background.base}) !important;
  color: var(${this.themeVarService.default.text.secondary}) !important;
  
  .text-content, #user-profile, #user-script-list {
    background-color: transparent !important;
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    color: var(${this.themeVarService.default.text.secondary}) !important;
    
    ul li a {
      color: var(${this.themeVarService.default.text.secondary}) !important;
      
      &:hover {
        color: var(${this.themeVarService.link.default.text}) !important;
      }
      
      i {
        font-style: normal !important;
      }
    }
  }
  
  a {
    /* 非脚本链接 */
    &:not(.script-link) {
      ${this.commonPage.linkStyles()}
    }
    
    /* 脚本链接 */
    &.script-link {
      ${this.commonPage.functionalLinkStyles()}
    }
  }
  
  > *  {
    padding: 20px !important;
  }
  
  #about-user {
    /* 作者名称 */
    > h2 {
      display: inline-flex !important;
      align-items: center;
      justify-content: center;
      text-decoration: none !important;
      position: relative;
      color: var(${this.themeVarService.default.text.primary}) !important;
      
      /* 作者图标 */
      &::before {
        ${this.stylesService.inlinePseudo.icon({ backgroundImageId: ICON_IDS.role.author, size: 24 })}
      }
    }
    /* 个人资料 */
    #user-profile {
      /* 简介 */
      h1 {
        ${BLOCKQUOTE_STYLES.BASE}
      }
    }
  }
  
  /* 库 */
  #user-library-script-list {
    background: transparent !important;
    box-shadow: none !important;
    border: none !important;
    
    .${AppStyleCollections.GreasyFork.SCRIPT_META_CONTAINER} {
      display: none !important;
    }
  }
}
`
  }
}
